var t = require;
var e = module;
var o = exports;
var i, n = this && this.__extends || (i = function(t, e) {
    return (i = Object.setPrototypeOf || {
        __proto__: []
    }
    instanceof Array &&
    function(t, e) {
        t.__proto__ = e
    } ||
    function(t, e) {
        for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o])
    })(t, e)
},
function(t, e) {
    function o() {
        this.constructor = t
    }
    i(t, e),
    t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o)
}),
a = this && this.__decorate ||
function(t, e, o, i) {
    var n, a = arguments.length,
    r = a < 3 ? e: null === i ? i = Object.getOwnPropertyDescriptor(e, o) : i;
    if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, o, i);
    else for (var s = t.length - 1; s >= 0; s--)(n = t[s]) && (r = (a < 3 ? n(r) : a > 3 ? n(e, o, r) : n(e, o)) || r);
    return a > 3 && r && Object.defineProperty(e, o, r),
    r
};
Object.defineProperty(o, "__esModule", {
    value: !0
});
var r = t("CarConstant"),
s = t("GlobalUserData"),
l = t("Hint"),
c = t("BroadCastMessage"),
d = t("Util"),
h = t("HallConstant"),
p = t("AssemblyItem"),
u = t("GoldFlyAnim"),
f = cc._decorator,
m = f.ccclass,
_ = f.property,
y = function(t) {
    function e() {
        var e = null !== t && t.apply(this, arguments) || this;
        return e.pfb_assemblyItem = null,
        e.pfb_goldfly = null,
        e.node_item = null,
        e.lab_name = null,
        e.lab_level = null,
        e.lab_sellGold = null,
        e.node_iconGold = null,
        e.node_hp = null,
        e.node_elec = null,
        e.node_damage = null,
        e.assemblyItem = null,
        e._itemData = null,
        e.nSellGold = 0,
        e._parent = null,
        e.bSellEnd = !1,
        e
    }
    return n(e, t),
    e.prototype.init = function(t) {
        this._parent = t
    },
    e.prototype.updateView = function(t) {
        this._itemData = t,
        this.bSellEnd = !1,
        this.node.active = !0,
        this.onSetSellGold(t),
        this.setLabelString(t),
        this.createItem(t),
        this.setAttributeString(t)
    },
    e.prototype.onBtnSell = function() {
        this.bSellEnd && l.default.show("已经出售！"),
        this.playAudio(h.Audio_ID.btn_click),
        this.nSellGold > 0 && this.onSellHandle() ? (this.bSellEnd = !0, s.default.saveGoldData(!0, this.nSellGold), this.playGetGoldAnim(), l.default.show("出售成功！")) : l.default.show("出售失败，请稍后重试")
    },
    e.prototype.onBtnClose = function() {
        this.playAudio(h.Audio_ID.btn_click),
        this.node.active = !1
    },
    e.prototype.onSetSellGold = function(t) {
        t && t.level && (this.nSellGold = d.Util.transformSellGold(t.level), this.lab_sellGold.string = d.Util.transformGoldStr(this.nSellGold))
    },
    e.prototype.onSellHandle = function() {
        switch (this._itemData.type) {
            case r.Basics_Items_Type.body:
                s.default.saveOwnCarBodyData(!1, this._itemData, !1);
            break;
            case r.Basics_Items_Type.wheel:
                s.default.saveOwnWheelData(!1, this._itemData, !1);
            break;
            case r.Basics_Items_Type.weapon:
                s.default.saveOwnWeaponData(!1, this._itemData, !1);
            break;
            case r.Basics_Items_Type.tools:
                s.default.saveOwnToolsData(!1, this._itemData, !1);
            break;
            default: return ! 1;
        }
        return ! 0
    },
    e.prototype.playGetGoldAnim = function() {
        var t = this;
        this.playAudio(h.Audio_ID.get_gold);
        var e = cc.v3(200, cc.winSize.height, 0);
        d.Util.AnimFly(u.Fly_Type.Gold, this.pfb_goldfly, this.node_iconGold, e,
        function() {
            t._parent._hallControl.onSetOwnGold(!0)
        },
        function() {
            t._parent.onSellSucceed(),
            t.node.active = !1
        })
    },
    e.prototype.setAttributeString = function(t) {
        var e = [cc.v3(76, 108), cc.v3(76, 67), cc.v3(76, 26)],
        o = 0;
        t.hp ? (this.node_hp.active = !0, this.node_hp.position = e[o], o++, this.node_hp.getChildByName("label").getComponent(cc.Label).string = "" + d.Util.transformHpNum(t.hp, t.level)) : this.node_hp.active = !1,
        t.damage ? (this.node_damage.active = !0, this.node_damage.position = e[o], o++, this.node_damage.getChildByName("label").getComponent(cc.Label).string = "" + d.Util.transformDamageNum(t.damage, t.level)) : this.node_damage.active = !1,
        t.elec ? (this.node_elec.active = !0, this.node_elec.position = e[o], o++, this.node_elec.getChildByName("label").getComponent(cc.Label).string = "" + t.elec) : this.node_elec.active = !1
    },
    e.prototype.setLabelString = function(t) {
        switch (t.type) {
            case r.Basics_Items_Type.body:
                var e = r.GetCarBodyData(t.id);
            this.lab_name.string = "" + e.name,
            this.lab_level.string = (t.level || "1") + "级";
            break;
            case r.Basics_Items_Type.wheel:
                var o = r.GetCarWheelData(t.id);
            this.lab_name.string = "" + o.name,
            this.lab_level.string = (t.level || "1") + "级";
            break;
            case r.Basics_Items_Type.weapon:
                var i = r.GetCarWeaponData(t.id);
            this.lab_name.string = "" + i.name,
            this.lab_level.string = (t.level || "1") + "级";
            break;
            case r.Basics_Items_Type.tools:
                var n = r.GetCarToolsData(t.id);
            this.lab_name.string = "" + n.name,
            this.lab_level.string = (t.level || "1") + "级";
        }
    },
    e.prototype.createItem = function(t) {
        if (!this.assemblyItem) {
            var e = cc.instantiate(this.pfb_assemblyItem);
            e.position = cc.v3(0, 0, 0),
            this.node_item.addChild(e),
            this.assemblyItem = e
        }
        this.assemblyItem.getComponent(p.AssemblyItem).updateItem(null, !0, 0, t, !1, p.Assembly_Type.Attribute)
    },
    e.prototype.playAudio = function(t) {
        c.default.getInstance().SendMessage(h.Broadcast_Func.Audio, t)
    },
    a([_(cc.Prefab)], e.prototype, "pfb_assemblyItem", void 0),
    a([_(cc.Prefab)], e.prototype, "pfb_goldfly", void 0),
    a([_(cc.Node)], e.prototype, "node_item", void 0),
    a([_(cc.Label)], e.prototype, "lab_name", void 0),
    a([_(cc.Label)], e.prototype, "lab_level", void 0),
    a([_(cc.Label)], e.prototype, "lab_sellGold", void 0),
    a([_(cc.Node)], e.prototype, "node_iconGold", void 0),
    a([_(cc.Node)], e.prototype, "node_hp", void 0),
    a([_(cc.Node)], e.prototype, "node_elec", void 0),
    a([_(cc.Node)], e.prototype, "node_damage", void 0),
    a([m], e)
} (cc.Component);
o.default = y